package com.gitee.shiro.authc;


import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class Authc {

    public static void main(String[] args) {
        Factory<SecurityManager> factory =
                new IniSecurityManagerFactory("classpath:authc.ini");
        SecurityManager securityManager
                = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken("admin", "admin");
        try {
            subject.login(token);
            System.out.println("身份验证成功！");
        }catch (AuthenticationException e){
            System.out.println("身份验证失败！");
        }
        System.out.println(subject.isAuthenticated());
        subject.logout();
    }
}
